var maxtime = 60*60;

function CountDown() {
	if (maxtime > 0) {
		--maxtime;
		hours = Math.floor(maxtime / 60);
		minutes = Math.floor(maxtime / 60);
		seconds = Math.floor(maxtime % 60);
		msg = "距离结束还有"+hours+"小时" + minutes + "分" + seconds + "秒";
		document.all["timer"].innerHTML = msg;
	} else {
		clearInterval(timer);
		var timea = document.getElementsByClassName("timer_a");
		for (var i = 0; i < timea.length; i++) {
			$(".timer_a").removeAttr('href');
			$(".timer_a").removeAttr('onclick');
			timea[i].style.cursor = "not-allowed";
			timea[i].style.backgroundColor = "#cccccc";
			timea[i].style.border="1px solid #cccccc"
		}
	}
}
timer = setInterval("CountDown()", 1000);

window.onload = function() {
				var APP_ID = 'eG22PNfwqck3fDTem41ACiNU-gzGzoHsz';
				var APP_KEY = 'Y8VoXz0cIzsJVbpctUAJXAAh';
				AV.init({
					appId: APP_ID,
					appKey: APP_KEY
				});
				pddenglu();
				var currentUser = AV.User.current();
				updateProduct1();
				updateProduct2();
				updateProduct3();
				updateProduct4();
			}
		function pddenglu() {
	currentUser = AV.User.current();
	href = "denglu.html?RetUrl=" + getPageUrl() + "&" + geturl();
	$(".top_a ul li").eq(1).html("<a href=" + href + ">登录</a>")
	if(currentUser) {
		$(".top_a ul li").eq(0).html("欢迎【" + currentUser.attributes.username + "】|");
		$(".top_a ul li").eq(1).html("<a>退出登录</a>");
		$(".top_a ul li").eq(1).bind("click", function() {
			localStorage.clear();
			location.href = location.href;
		})
	}
}

function getPageUrl() {
	var index = location.pathname.lastIndexOf("/") + 1;
	var i = location.pathname.substr(index);
	//			console.log(i)
	return escape(i)
}

function geturl() {
	var u = location.search;
	u = u.substring(1, (u.length))
	console.log(u);
	return u;
}
			function updateProduct1() {
				// LeanCloud - 查询
				// https://leancloud.cn/docs/leanstorage_guide-js.html#查询
				var query = new AV.Query('Canvas');
				query.descending('createdAt');
				query.find().then(function(products) {
					for(var i=0;i<3;i++){
						var divtj='<div class="timer_div">';
						divtj+='<div class="timer_d1"><img src="' + products[i].attributes.image[0] + '"></div>';
						divtj+='<div class="timer_d2"><p>'+products[i].attributes.title+'</p>';
						divtj+='<p>作者：'+products[i].attributes.author+'</p>';
						divtj+='<p class="timer_d2_p"><span>￥'+products[i].attributes.price+'00</span><a class="timer_a"  href="ComDet.html?biao=Canvas&id='+products[i].attributes.inid+'">马上抢</a></p></div>';
						$("#xianshi").append(divtj);
					}
//					$('#addimg").html(products[0].attributes.title);
					// 查询到商品后，在前端展示到相应的位置中

				}).catch(function(error) {
					alert(JSON.stringify(error));
				});

			}
			function updateProduct2() {
				// LeanCloud - 查询
				// https://leancloud.cn/docs/leanstorage_guide-js.html#查询
				var query = new AV.Query('Ancient_Porcelai');
				query.descending('createdAt');
				query.find().then(function(products) {
					for(var i=0;i<3;i++){
						var divtj='<div class="timer_div">';
						divtj+='<div class="timer_d1"><img src="' + products[i].attributes.image[0] + '"></div>';
						divtj+='<div class="timer_d2"><p>'+products[i].attributes.title+'</p>';
						divtj+='<p>作者：'+products[i].attributes.author+'</p>';
						divtj+='<p class="timer_d2_p"><span>￥'+products[i].attributes.price+'00</span><a class="timer_a"  href="ComDet.html?biao=Canvas&id='+products[i].attributes.inid+'">马上抢</a></p></div>';
						$("#xianshi").append(divtj);
					}
//					$('#addimg").html(products[0].attributes.title);
					// 查询到商品后，在前端展示到相应的位置中

				}).catch(function(error) {
					alert(JSON.stringify(error));
				});

			}
			function updateProduct3() {
				// LeanCloud - 查询
				// https://leancloud.cn/docs/leanstorage_guide-js.html#查询
				var query = new AV.Query('Contemporary_Crafts');
				query.descending('createdAt');
				query.find().then(function(products) {
					for(var i=0;i<3;i++){
						var divtj='<div class="timer_div">';
						divtj+='<div class="timer_d1"><img src="' + products[i].attributes.image[0] + '"></div>';
						divtj+='<div class="timer_d2"><p>'+products[i].attributes.title+'</p>';
						divtj+='<p>作者：'+products[i].attributes.author+'</p>';
						divtj+='<p class="timer_d2_p"><span>￥'+products[i].attributes.price+'00</span><a class="timer_a"  href="ComDet.html?biao=Canvas&id='+products[i].attributes.inid+'">马上抢</a></p></div>';
						$("#xianshi").append(divtj);
					}
//					$('#addimg").html(products[0].attributes.title);
					// 查询到商品后，在前端展示到相应的位置中

				}).catch(function(error) {
					alert(JSON.stringify(error));
				});

			}
			function updateProduct4() {
				// LeanCloud - 查询
				// https://leancloud.cn/docs/leanstorage_guide-js.html#查询
				var query = new AV.Query('Chinese_Painting');
				query.descending('createdAt');
				query.find().then(function(products) {
					for(var i=0;i<3;i++){
						var divtj='<div class="timer_div">';
						divtj+='<div class="timer_d1"><img src="' + products[i].attributes.image[0] + '"></div>';
						divtj+='<div class="timer_d2"><p>'+products[i].attributes.title+'</p>';
						divtj+='<p>作者：'+products[i].attributes.author+'</p>';
						divtj+='<p class="timer_d2_p"><span>￥'+products[i].attributes.price+'00</span><a class="timer_a"  href="ComDet.html?biao=Canvas&id='+products[i].attributes.inid+'">马上抢</a></p></div>';
						$("#xianshi").append(divtj);
					}
//					$('#addimg").html(products[0].attributes.title);
					// 查询到商品后，在前端展示到相应的位置中

				}).catch(function(error) {
					alert(JSON.stringify(error));
				});

			}
